<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true">
        <el-row>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <el-input v-model="params.name"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="维护状态">
              <!-- 0未维护 1已维护-->
              <el-select name id clearable v-model="params.isExist">
                <el-option value="1" label="已维护"></el-option>
                <el-option value="0" label="未维护"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="创建时间" width="236">
              <el-date-picker
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                v-model="time"
                :default-time="['00:00:00', '23:59:59']"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结算模式">
              <el-select name id clearable v-model="params.settlementType">
                 <el-option :value="null" label="全部"></el-option>
                <el-option :value="1" label="预存款模式"></el-option>
                <el-option :value="0" label="回款模式"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button style="margin-left:60px" type="primary" @click="searchfun">查询</el-button>
            <el-button
              v-if="permissionJson.indexOf('AdminHospitalInformationProvider.export') !=-1"
              type="primary"
              @click="exfun"
            >导出</el-button>
            <el-button
              v-if="permissionJson.indexOf('AdminHospitalInformationProvider.createHospitalInformation') !=-1"
              @click="addfun()"
              type="primary"
            >新增</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="table" v-loading="tablaLoading">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" align="center" :index="table_index" width="50"></el-table-column>
        <el-table-column prop="name" align="center" label="医院名称" width="180"></el-table-column>
        <el-table-column prop="reimbursementRatio" align="center" label="回款比率" width="180">
          <template slot-scope="scope">
            <span
              v-if="scope.row.reimbursementRatio && scope.row.reimbursementRatio!=0"
            >{{scope.row.reimbursementRatio}}%</span>
          </template>
        </el-table-column>
        <el-table-column prop="settlementType" align="center" label="结算模式"></el-table-column>
        <el-table-column prop="settlementFee" align="center" label="入驻费"></el-table-column>
        <el-table-column prop="time" align="center" label="回款比率生效时间"></el-table-column>
        <el-table-column prop="updatedAt" align="center" label="审核通过时间"></el-table-column>
        <el-table-column prop align="center" label="医院基础信息">
          <template slot-scope="scope">
            <span v-if="scope.row.isExist==0">未维护</span>
            <span v-if="scope.row.isExist==1">已维护</span>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" align="center" label="备注">
          <template slot-scope="scope">
            <div class="text-overflow">{{scope.row.remarks}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="createdBy" align="center" label="创建人">
          <template slot-scope="scope">
            <span>{{scope.row.createdBy | userinfo}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createdAt" align="center" label="创建时间"></el-table-column>
        <el-table-column align="center" label="开户状态">
          <template slot-scope="scope">
            <span v-if="scope.row.accountOpenStatus==3">开户失败</span>
            <span v-if="scope.row.accountOpenStatus==2">开户成功</span>
            <span v-if="scope.row.accountOpenStatus=='0'">未开户</span>
            <span v-if="scope.row.accountOpenStatus=='1'">待审核</span>
          </template>
        </el-table-column>
        <el-table-column prop="accountOpenFailReasons" align="center" label="开户失败原因"></el-table-column>
        <el-table-column prop align="center" label="标识">
          <template slot-scope="scope">
            <span v-if="scope.row.dataFlag==0">新数据</span>
            <span v-if="scope.row.dataFlag==1">老数据</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <div>
              <el-button
                v-if="permissionJson.indexOf('AdminHospitalInformationProvider.updateHospitalInformation') !=-1 &&(scope.row.accountOpenStatus!=1)"
                @click="edit(scope.row,1)"
                type="text"
              >编辑</el-button>
              <el-button
                v-if="permissionJson.indexOf('AdminHospitalInformationProvider.hospitalInformationDetail') !=-1"
                @click="edit(scope.row,2)"
                type="text"
              >详情</el-button>
              <!-- -->
              <span v-if="permissionJson.indexOf('AdminHospitalProvider.createHospital') !=-1">
                <el-button
                  v-if="scope.row.isExist==0&&scope.row.dataFlag==0"
                  type="text"
                  @click="edit(scope.row)"
                >医院信息维护</el-button>
              </span>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block" style="margin: 40px 0;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import hospitalEnter from "@/api/hospitalEnry";
import { exportfile } from "@/api/exporfile";
import filter from "@/assets/filter.js";
export default {
  name: "hospitalentery",
  data() {
    return {
      tablaLoading: false,
      time: "",
      total: 0,
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      params: {
        time: "",
        pageNum: 1,
        pageSize: 10,
        name: "", //医院名称
        isExist: "", //维护状态 0未维护 1已维护
        examineStatus: null, //审核状态 0为待审核 1为审核通过 2为审核驳回
        createdAtStartime: "", //创建时间yyyy-MM-dd
        createdAtEndtime: "" //创建时间yyyy-MM-dd
      },

      tableData: []
    };
  },
  mounted() {
    this.list();
  },
  watch: {
    time() {
      console.log(this.time);
      this.params.createdAtStartime = this.time ? this.time[0] : "";
      this.params.createdAtEndtime = this.time ? this.time[1] : "";
    }
  },
  methods: {
    table_index(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + index + 1;
    },
    exfun() {
      hospitalEnter.exportfun(this.params).then(res => {
        exportfile(res);
      });
    },
    searchfun() {
      this.params.pageNum = 1;

      this.list();
    },
    list() {
      (this.tablaLoading = true),
        hospitalEnter.list(this.params).then(res => {
          console.log(res);
          if (res.data.code == 0) {
            this.total = res.data.data.count;
            this.tableData = res.data.data.list;
            this.tablaLoading = false;
          } else {
            this.$message.warning(res.data.msg);
          }
          this.loadings = false;
        });
    },
    addfun() {
      this.$router.push({ name: "enteryAdd", query: { type: 0 } });
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list();
    },
    edit(datas, type) {
      let id;
      console.log(datas);
      id = datas.hospitalInformationId;
      if (type === undefined) {
        this.$router.push({
          name: "hospitalEdit",
          query: {
            hospitalname: datas.name,
            id: id,
            disable: "disable",
            type: 1
          }
        });
        return;
      }

      this.$router.push({
        name: "enteryAdd",
        query: { type: type, id: id }
      });
    }
  }
};
</script>   
<style scoped>
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
.text-overflow {
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
</style>